package com.server.llh.llhserverwork.adapter;

/**
 * Created by ZTF on 2017-06-23.
 */

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.activity.server.LlhSubscribeActivity;
import com.server.llh.llhserverwork.bean.SerStockDetailWapBean;
import com.server.llh.llhserverwork.port.SubscribeInterface;

import java.util.List;

/**
 * 预约服务项显示
 *
 * @author lelaohui
 *
 */
public class DetailListAdapter extends BaseAdapter {
    List<SerStockDetailWapBean> serStockDetailList;
    SubscribeInterface subscribeInterface;
    Context context;
    public DetailListAdapter(Context context,List<SerStockDetailWapBean> serStockDetailList) {
        this.serStockDetailList = serStockDetailList;
        this.context=context;
    }
 public void registCallBack(LlhSubscribeActivity subscribeInterface){
     this.subscribeInterface=subscribeInterface;
 }
    @Override
    public int getCount() {
        if (serStockDetailList == null || serStockDetailList.size() == 0) {
            return 0;
        }
        return serStockDetailList.size();
    }

    @Override
    public Object getItem(int position) {
        return serStockDetailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView,
                        ViewGroup parent) {
        DetailHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater
                    .from(context)
                    .inflate(R.layout.stock_detail_list_item, parent, false);
            holder = new DetailHolder();
            holder.server_content = (TextView) convertView
                    .findViewById(R.id.server_content);
            holder.server_content_num = (TextView) convertView
                    .findViewById(R.id.server_content_num);
            holder.server_surplus_num = (TextView) convertView
                    .findViewById(R.id.server_surplus_num);
            holder.server_rule_content = (TextView) convertView
                    .findViewById(R.id.server_rule_content);
            holder.server_time_content = (TextView) convertView
                    .findViewById(R.id.server_time_content);
            holder.btn_uplode = (TextView) convertView
                    .findViewById(R.id.btn_uplode);
            holder.server_time = (TextView) convertView
                    .findViewById(R.id.server_time);
            holder.server_rule = (TextView) convertView
                    .findViewById(R.id.server_rule);

            convertView.setTag(holder);
        } else {
            holder = (DetailHolder) convertView.getTag();
        }
        final SerStockDetailWapBean infoData = serStockDetailList
                .get(position);
        holder.btn_uplode.setText("选择");
        holder.server_content.setText("    " + infoData.getServiceName());
        holder.server_content_num.setVisibility(View.GONE);
        holder.server_rule.setTextSize(20);
        holder.server_rule.setText("     "+"服务规则:");
        holder.server_surplus_num.setText("");
        holder.server_rule_content.setText("" + infoData.getRuleStr());
        // holder.server_time_content.setText("一天执行" +
        // infoData.getExecNumDay()+"次");
        holder.server_time.setText("");
        holder.server_time_content.setText("");
        holder.btn_uplode.setText("确定");

        holder.btn_uplode.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                int currentNum = infoData.getCurrentNum();
                if (currentNum > 0) {
                    Log.d("currentNum","serStockDetailWapBean=="+infoData.getExecNumDay() );
                    subscribeInterface.callBack(infoData);
                } else {

                }
            }
        });
        return convertView;
    }

    class DetailHolder {
        TextView server_content, server_time_content, server_content_num,
                server_surplus_num, server_rule_content, btn_uplode, server_time,server_rule;

    }
}

